///
/// The MyPage_Load function handles load event for the page..
///
/// The object that raised the load event.
/// The object that contains the event data of the load event.
private void MyPage_Load(System.Object sender, System.EventArgs e)
{
if (!(this.Page.IsPostBack))
{
// Get the resource directory of the application. It is "bin" for .NET Framework 1.1 applications
// and "App_GlobalResources" for .NET Framework 2.0 applications
string resourceDir = "";
string runtimeVersion = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion();
if (runtimeVersion.IndexOf("v2") == -1)
{
resourceDir = "bin";
}
else
{
resourceDir = "App_GlobalResources";
}
string resourcePath = this.Request.PhysicalApplicationPath + resourceDir + "\\";
if (System.IO.Directory.Exists(resourcePath))
{
// Find all the resource files of the type AppName.culture.resx
string[] resourceFiles = System.IO.Directory.GetFiles(resourcePath, "*.*.resx");
foreach (string resourceFile in resourceFiles)
{
// collect the resource objects and count the occurrences of the names
System.IO.FileInfo finfo = new System.IO.FileInfo(resourceFile);
// Get the file name
string fileName = finfo.Name;
// Split the filename by the "."
string splitBy = ".";
string[] namePieces = fileName.Split(splitBy.ToCharArray());
int length = namePieces.Length;
int index = length - 2;
// Get the culture name portion of the filename like "en-US"
string cultureName = namePieces[index];
// Create a CultureInfo object to represent the culture
System.Globalization.CultureInfo culutreInfo = new System.Globalization.CultureInfo(cultureName);
// Populate the cultures list
ListItem li = new ListItem(culutreInfo.DisplayName, culutreInfo.Name);
if (!(this.LanguageList.Items.Contains(li)))
{
this.LanguageList.Items.Add(li);
if (System.Threading.Thread.CurrentThread.CurrentUICulture.Name == culutreInfo.Name)
{
// Select the current culture of the application
li.Selected = true;
}
}
}
}
}
}
|